package net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpEchoCLient {
    private Socket socket=null;
    public TcpEchoCLient(String serverIp,int serverPort) throws IOException {
        socket=new Socket(serverIp,serverPort);
    }

    public void start(){
        try (InputStream inputStream=socket.getInputStream();
             OutputStream outputStream=socket.getOutputStream()){
            Scanner scannerConle=new Scanner(System.in);
            Scanner scannernetWork=new Scanner(inputStream);
            while (true){
                if (!scannerConle.hasNext()){
                    break;
                }
                String requst=scannerConle.next();
                PrintWriter printWriter=new PrintWriter(outputStream);
                printWriter.println(requst);
                printWriter.flush();

                String respone=scannernetWork.next();
                System.out.println(respone);
            }



        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws IOException {
        TcpEchoCLient cLient=new TcpEchoCLient("127.0.0.1",9090);
        cLient.start();
    }
}
